class Notifier < ActionMailer::Base

def notify(template, recips, object, lang)
  recipients recips
  lang = DEFAULT_LANG if lang.nil? or lang == ''
  email = Email.find(:first,:conditions=>["name = ? and lang = ?",template,lang])
  from "Trikr<no-reply@trikr.com>"
  content_type "text/html"
  
  #object is User
  if object.class.name == "User"
    company = object.company
    subject Liquid::Template.parse(email.subject).render( 
	   'user' => object.attributes, 'company' => company.attributes )
    body Liquid::Template.parse( CGI.unescapeHTML(email.body) ).render( 
	   'user' => object.attributes,
	   'company' => company.attributes 
	   )
  #object is Message
  elsif object.class.name == "Message"
    project = object.project
    company = project.company
    user    = object.user
    subject Liquid::Template.parse(email.subject).render( 
	    'message' => object.attributes,
	    'company' => company.attributes,
	    'user'    => user.attributes,
	    'project' => project.attributes
	)
    body Liquid::Template.parse( CGI.unescapeHTML(email.body) ).render( 
	    'message' => object.attributes,
	    'company' => company.attributes,
	    'user'    => user.attributes,
	    'project' => project.attributes
	)
  #object is Message
  elsif object.class.name == "Milestone"
    project = object.project
    company = project.company
    user    = object.user
    subject Liquid::Template.parse(email.subject).render( 
	    'milestone' => object.attributes,
	    'company' => company.attributes,
	    'user'    => user.attributes,
	    'project' => project.attributes
	)
    body Liquid::Template.parse( CGI.unescapeHTML(email.body) ).render( 
	    'milestone' => object.attributes,
	    'company' => company.attributes,
	    'user'    => user.attributes,
	    'project' => project.attributes,
	    'due_at'  => object.due_at.strftime('%Y-%m-%d')
	)
  #object is Files
  else
    project = object.first.project
    company = project.company
    subject Liquid::Template.parse(email.subject).render( 
	   'project' => project.attributes, 'company' => company.attributes )
    body Liquid::Template.parse( CGI.unescapeHTML(email.body) ).render( 
	   'files' => object.collect{|f| f.name}.join(","),
	   'project' => project.attributes,
	   'company' => company.attributes 
	   )
  end
end

end
